package com.zzyl.nursing.controller;

import com.zzyl.common.annotation.Log;
import com.zzyl.common.core.controller.BaseController;
import com.zzyl.common.core.domain.AjaxResult;
import com.zzyl.common.core.domain.R;
import com.zzyl.common.core.page.TableDataInfo;
import com.zzyl.common.enums.BusinessType;
import com.zzyl.common.utils.poi.ExcelUtil;
import com.zzyl.nursing.domain.Room;
import com.zzyl.nursing.service.IRoomService;
import com.zzyl.nursing.vo.RoomVo;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.media.Schema;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 房间Controller
 *
 * @author ruoyi
 * @date 2025-10-20
 */
@RestController
@RequestMapping("/elder/room" )
@Tag(name = "房间相关接口" )
public class RoomController extends BaseController {
    @Autowired
    private IRoomService roomService;

    /**
     * 查询房间列表
     */
    @PreAuthorize("@ss.hasPermi('nursing:room:list')" )
    @GetMapping("/list" )
    @Operation(summary = "查询房间列表" )
    public TableDataInfo list(Room room) {
        startPage();
        List<Room> list = roomService.selectRoomList(room);
        return getDataTable(list);
    }

    /**
     * 导出房间列表
     */
    @PreAuthorize("@ss.hasPermi('nursing:room:export')" )
    @Log(title = "房间" , businessType = BusinessType.EXPORT)
    @Operation(summary = "导出房间列表" )
    @PostMapping("/export" )
    public void export(HttpServletResponse response, Room room) {
        List<Room> list = roomService.selectRoomList(room);
        ExcelUtil<Room> util = new ExcelUtil<Room>(Room.class);
        util.exportExcel(response, list, "房间数据" );
    }

    /**
     * 获取房间详细信息
     */
    @PreAuthorize("@ss.hasPermi('nursing:room:query')" )
    @GetMapping("/{id}" )
    @Operation(summary = "获取房间详细信息" )
    public R<RoomVo> getInfo(@Schema(title = "房间ID" )
                             @PathVariable("id" ) Long id) {
        return R.ok(roomService.selectRoomById(id));
    }

    /**
     * 新增房间
     */
    @PreAuthorize("@ss.hasPermi('nursing:room:add')" )
    @Log(title = "房间" , businessType = BusinessType.INSERT)
    @PostMapping
    @Operation(summary = "新增房间" )
    public AjaxResult add(@Schema(title = "房间实体" ) @RequestBody Room room) {
        return toAjax(roomService.insertRoom(room));
    }

    /**
     * 修改房间
     */
    @PreAuthorize("@ss.hasPermi('nursing:room:edit')" )
    @Log(title = "房间" , businessType = BusinessType.UPDATE)
    @PutMapping
    @Operation(summary = "修改房间" )
    public AjaxResult edit(@Schema(title = "房间实体" ) @RequestBody Room room) {
        return toAjax(roomService.updateRoom(room));
    }

    /**
     * 删除房间
     */
    @PreAuthorize("@ss.hasPermi('nursing:room:remove')" )
    @Log(title = "房间" , businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}" )
    @Operation(summary = "删除房间" )
    public AjaxResult remove(@Schema(title = "房间ID数组" ) @PathVariable Long[] ids) {
        return toAjax(roomService.deleteRoomByIds(ids));
    }
}
